# 集合的创建
s1 = set()
print(s1)  # set()
s2 = {1, 2, 3, 4, 1, 2}
print(s2)  # {1, 2, 3, 4}
s3 = set((1, 2, 3))
print(s3)  # {1, 2, 3}
s4 = set([5, 6, 7])
print(s4)  # {5, 6, 7}
s5 = set('hello')
print(s5)  # {'o', 'e', 'h', 'l'}
s6 = set({1: 2, 'hello': 'world'})
print(s6)  # {1, 'hello'}

# 常用操作
print(1 in s2)  # True
print(len(s2))  # 4
del s1

# 集合的遍历
for i in s2:
    print(i)

# 常用方法
s2.update({"name", "age"})
print(s2)  # {1, 2, 3, 4, 'name', 'age'}
s2.add(6)
print(s2)
s2.remove('name')
print(s2)

# 交集& 并集|
s7 = {1, 2, 3}
s8 = {2, 4, 6}
print(s7 & s8)  # {2}
print(s7 | s8)  # {1, 2, 3, 4, 6}

# 计算各个分数都有几个学生
score = [80, 70, 60, 80, 70, 60, 40]
s = set(score)
d = {}
print(s)
for i in s:
    num = score.count(i)
    d[i] = num
print(d)
for k, v in d.items():
    print("%d分的学生有%d" %(k, v))